//
// Created by grainlee on 16/9/21.
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;

void generate(int left, int right, string s, vector<string> &res){
    if (left == 0 && right == 0){
        res.push_back(s);
        return ;
    }
    if (left > 0){
        generate(left -1 , right,s+'(',res);
    }
    if (right > 0 && left < right){
        generate(left, right - 1,s+')',res);
    }
}


vector<string> generateParenthesis(int n) {
    vector<string> res;
    generate(n,n,"",res);
    return res;
}

int main (){
    vector<string> ss =generateParenthesis(3);
    for (int i =0 ; i < ss.size();i++){
        cout << ss[i] << endl;
    }
}